package testgrails

//B-1: Bids have the following required fields: amount and date/time of bid (unit test)
//B-2: Bids are required to be for a Listing (unit test)
//B-3: Bids are required to have a bidder (Customer) (unit test)
//B-4: A Listing has a list of Bids for that Listing (unit test)
//B-5: The Bid amount must be at least .50 higher than the previous Bid for the same listing (integration test)
//B-6: When a Listing is saved, any new Bids added for the listing must be saved (integration test)


import grails.test.mixin.*
import org.junit.*

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Bid)
class BidTests {
	def bid
	def customer
	def listing
	
	void setUp()
	{
		customer = new Customer(emailAddress: 'bushrat@gmail.com', password: '1234567' , dateCreated: new Date())
		listing = new Listing(name:'name1',endDate:new Date() + 1,startingBidPrice: 100.0)
	}
	//B-1: Bids have the following required fields: amount and date/time of bid (unit test)
    void testRequiredFields() {
     bid = new Bid(amount: null,bidDate: null)
	 assertFalse(bid.validate(['amount']))
	 assertFalse(bid.validate(['bidDate']))
	 
    }
	//B-2: Bids are required to be for a Listing (unit test)
	void testRequiredBidListing()
	{
		def bid = new Bid( amount:3.0, bidDate: new Date(), bidder: customer )
		assertTrue(bid.validate(['amount']))
		assertTrue(bid.validate(['bidDate']))
		assertTrue(bid.validate(['customer']))
		
		assertNull( bid.getListing() )
		assertFalse( bid.validate() )
		
	}
	//B-3: Bids are required to have a bidder (Customer) (unit test)
	void testRequiredBidder() {
		def bid = new Bid( amount:2.0, currentAmount:1.0, bidDate: new Date())
		assertNull( bid.getBidder())
		assertFalse(bid.validate())
		
		bid.bidder = customer
		assertTrue(bid.validate(['customer']))
	 }
	
	//B-4: A Listing has a list of Bids for that Listing (unit test)
	void testListOfBids() {
		def bid = new Bid( amount:1.0, bidDate: new Date(), bidder: customer )
		List bids = new ArrayList()
		bids.add(bid)
		
		def listing = new Listing(name:'name1',endDate:new Date() + 1,startingBidPrice: 100.0, bids: bids)
		assertNotNull( listing.bids )
		assertTrue( listing.bids.size() > 0 )
	 }
	//This is a test commit
}
